﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using iBuproModel;
using System.ComponentModel.DataAnnotations;
using System.Web.Mvc;
using iBuproModel.Repositories.Classes;
using System.Collections;
using IBupro.Models.Classes;
using iBuproModel.Repositories;
using iBuproModel.Repositories.Interfaces;

namespace IBupro.Models
{
    public class StudentPlanModel : CustomModel
    {

        [Required(ErrorMessage="You must enter name")]
        public string Name { get; set; }

        [Required(ErrorMessage = "You must enter shortcut")]
        public string Shortcut { get; set; }

        public MultiSelectList MultiSelectListSubjects(string [] selectedItems)
        {
            ISubjectRepository repository = repositoryService.SubjectRepositoryCreateInstace();

            IEnumerable subjects =  from s in repository.GetAll().ToList()
                                    select new
                                    {
                                        Id = s.Id,
                                        Name = String.Format("({0}) {1}", s.Shortcut, s.Name)
                                    };

            return new MultiSelectList(subjects, "Id", "Name",selectedItems);
        }

        public MultiSelectList MultiSelectListSubjects()
        {
            return MultiSelectListSubjects(null);
        }
        public IEnumerable<int> SelectedSubjects { get; set; }


        public MultiSelectList MultiSelectListStudentFields(string[] selectedItems)
        {
            IStudentFieldRepository repository = repositoryService.StudentFieldRepositoryCreateInstance();

            IEnumerable fields = from f in repository.GetAll().ToList()
                                 select new
                                 {
                                     Id = f.Id,
                                     Name = String.Format("({0}) {1}", f.Shortcut, f.Name)
                                 };


            return new MultiSelectList(fields, "Id", "Name", selectedItems);
        }

        public MultiSelectList MultiSelectListStudentFields()
        {
            return MultiSelectListStudentFields(null);
        }
        public IEnumerable<int> SelectedFields { get; set; }

        public StudentPlanModel()
        {}

       

    }


}